#include "MatchAlarmReportRequest.h"


MatchAlarmReportRequest::MatchAlarmReportRequest(const QList<MatchAlarmList> &alarmList, const QString &factoryNo, const QString &transId, const QDateTime &eventTime, const QString &eventUser, const QString &machineNo):
    alarmList(alarmList),
    factoryNo(factoryNo),
    transId(transId),
    eventTime(eventTime),
    eventUser(eventUser),
    machineNo(machineNo)
{

}

QByteArray MatchAlarmReportRequest::toJson() const
{
    QJsonObject json;
    int randomNumber = QRandomGenerator::global()->bounded(10000,100000);
    QString dateTime = QDateTime::currentDateTime().toString("yyyyMMddhhmmssSSS");

    json["factoryNo"] = factoryNo;
    json["transId"] = QString("%1%2").arg(dateTime).arg(randomNumber);
    json["eventTime"] = eventTime.toString("yyyy-mm-dd hh:mm:ss");
    json["eventUser"] = eventUser;
    json["machineNo"] = machineNo;

    QJsonArray alarmArray;

    for(const auto& item:alarmList)
    {
        QJsonObject alarmJson;
        alarmJson["alarmCode"]=item.alarmCode;
        alarmJson["status"] = item.status;
        alarmArray.append(alarmJson);
    }
    json["alarmList"]=alarmArray;
    return QJsonDocument(json).toJson();
}

QString MatchAlarmReportRequest::getEndPoint() const
{
    return "/api/getech-mes/IotController/MachAlarmReport";
}
